/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.jboss.seam.example.booking.utils;

import java.util.List;
import org.hibernate.search.jpa.FullTextEntityManager;
import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.AutoCreate;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Scope;
import org.jboss.seam.example.booking.entity.Hotel;

/**
 *
 * @author RHO
 */
@AutoCreate
@Scope(ScopeType.EVENT)
@Name("searchReIndex")
public class SearchReIndex {
    @In 
    private FullTextEntityManager entityManager;
    
    public String reindex() {
        final List<Hotel> entries = entityManager.createQuery("select b from Hotel b").getResultList();
        for (Hotel b : entries) {
            entityManager.index(b);
        }
        return null;
    }
}
